//
//  SearchView.m
//  SG
//
//  Created by FISH on 2018/4/21.
//  Copyright © 2018年 yimindai. All rights reserved.
//

#import "SearchView.h"

@implementation SearchView

-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self){
    }
    return self;
}

#pragma mark 实现searchView方法
-(void)createSearchView:(NSString*)placeholer
{
    self.placeholder = placeholer;
    //设置textField的样式
    self.borderStyle = UITextBorderStyleNone;
    //设置键盘的return键 的样式 我们更改为search字样
    self.returnKeyType = UIReturnKeySearch;
    
    
    UIView *rightView = [[UIView alloc]initWithFrame:CGRectMake(0, 10, 30, 30)];//左边的小图片
    rightView.userInteractionEnabled = YES;
    self.rightView = rightView;//移到左边
    self.rightViewMode = UITextFieldViewModeAlways;//设置为始终保持黄色小图片
    //创建imageView对象
    UIImageView * imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rightView.frame.size.width,  rightView.frame.size.height)];
    //设置 imgVIew的用户可交互性
    imgView.userInteractionEnabled = YES;
    //给 imgView赋值  tabbar_discover是一个放大镜图片
    imgView.image = [UIImage imageNamed:@"tabbar_discover"];
    //设置self (textField)的 rightView属性和 rightViewMode的属性
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    [rightView addSubview:imgView];

    //向 这张图片添加一个手势
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(btnClick:)];
    [imgView addGestureRecognizer:tap];
}

//实现按钮点击事件
-(void)btnClick:(UIButton *)btn
{
    DLog(@"实现按钮点击事件");
}

@end
